﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MailSizeLabeler
{
    class RangeMailboxDef
    {
        private static System.Globalization.CultureInfo _cultureInfo = new System.Globalization.CultureInfo("en-US");
        private string _name;
        private int _minMailSize;
        private int _maxMailSize;

        public string Name
        {
            get { return _name; }
        }

        public RangeMailboxDef(string name, int minMailSize, int maxMailSize)
        {
            _name = name;
            _minMailSize = minMailSize;
            _maxMailSize = maxMailSize;
        }

        public bool IsInRange(int size)
        {
            return (size >= _minMailSize) && (size < _maxMailSize);
        }

        public string GetIMAPSearchQuery()
        {
            if (_minMailSize > 0)
                return string.Format(_cultureInfo, "(LARGER {0}) (SMALLER {1})", _minMailSize - 1, _maxMailSize);
            else
                return string.Format(_cultureInfo, "(SMALLER {0})", _maxMailSize);
        }

        public static List<RangeMailboxDef> BuildRangeList()
        {
            List<RangeMailboxDef> list = new List<RangeMailboxDef>();

            list.Add(new RangeMailboxDef("Size 1M-2M", 1 * 1024 * 1024, 2 * 1024 * 1024));
            list.Add(new RangeMailboxDef("Size 2M-5M", 2 * 1024 * 1024, 5 * 1024 * 1024));
            list.Add(new RangeMailboxDef("Size 5M-10M", 5 * 1024 * 1024, 10 * 1024 * 1024));
            list.Add(new RangeMailboxDef("Size 10M-15M", 10 * 1024 * 1024, 15 * 1024 * 1024));
            list.Add(new RangeMailboxDef("Size 15M plus", 15 * 1024 * 1024, int.MaxValue));

            return list;
        }
    }
}
